Relatório - Histórico do progresso por tema

data <- merge(progressos, temas, by.x = "id_ext", by.y = "id_ext")
data_subset <- data[ , c("id_ext", "data_inicio")]  
data_by_column <- data[complete.cases(data_subset), ] %>% 
                  mutate(fase_local = ifelse(is.na(local), 
                                             fase_global, 
                                             paste(fase_global, local, sep=" - ")))

agenda_nacional <- data_by_column[is.na(data_by_column$data_fim), ]  %>% 
              filter(tema == "Agenda Nacional") %>% 
              group_by(fase_local) %>% 
              summarise(pls = n())
meio_ambiente <- data_by_column[is.na(data_by_column$data_fim), ]  %>% 
              filter(tema == "Meio Ambiente") %>% 
              group_by(fase_local) %>% 
              summarise(pls = n())
geral <- data_by_column[is.na(data_by_column$data_fim), ]  %>% 
              group_by(fase_local) %>% 
              summarise(pls = n())
p0 <- plot_ly(
    type = 'scatterpolar',
    fill = 'toself'
  ) %>%
  add_trace(
    r = geral$pls,
    theta = geral$fase_local,
    name = 'Geral'
  )  %>% 
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(0,35)
      )
    ),
    showlegend = F
  )

p <- plot_ly(
    type = 'scatterpolar',
    fill = 'toself'
  ) %>%
  add_trace(
    r = agenda_nacional$pls,
    theta = agenda_nacional$fase_local,
    name = 'Agenda Nacional'
  )  %>% 
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(0,15)
      )
    ),
    showlegend = F
  )

p2 <- plotly::plot_ly(
    type = 'scatterpolar',
    fill = 'toself'
  ) %>%
  plotly::add_trace(
    r = meio_ambiente$pls,
    theta = meio_ambiente$fase_local,
    name = 'Agenda Nacional'
  )  %>% 
  plotly::layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(0,15)
      )
    ),
    showlegend = F
  )

plotly::ggplotly(p0)
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
plotly::ggplotly(p)
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
plotly::ggplotly(p2)
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
hoje <-Sys.Date()
data_subset <- data[ , c("id_ext", "data_inicio", "data_fim", "tema")] 
progresso_data <- data_subset %>% 
  rowwise() %>% 
  filter(is.na(data_fim)) %>% 
  mutate(semanas = lubridate::time_length(lubridate::interval(
                                          lubridate::ymd(
                                          unlist(
                                          strsplit(as.character(data_inicio), " "))[1]), 
                                          lubridate::ymd(hoje)), "week")) %>% 
  filter(!is.na(data_inicio))

mediana_por_tema <- progresso_data %>% 
                    group_by(tema) %>% 
                    summarise(mediana = median(semanas))
## Warning: Grouping rowwise data frame strips rowwise nature
p <- ggplot2::diamonds %>% 
  plot_ly(
  x = ~mediana_por_tema$tema, 
  y = ~mediana_por_tema$mediana)

ggplotly(p)
## No trace type specified:
##   Based on info supplied, a 'bar' trace seems appropriate.
##   Read more about this trace type -> https://plot.ly/r/reference/#bar
summary(progresso_data$semanas)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.571  63.750 166.786 239.649 365.143 892.000
boxplot(progresso_data$semanas)

data_subset <- data[ , c("id_ext", "data_inicio", "data_fim", "tema", "fase_global", "apelido")]
data_by_column <- data[complete.cases(data_subset), ] %>% 
                  mutate(fase_local = ifelse(is.na(local), 
                                             fase_global, 
                                             paste(fase_global, 
                                                   local, 
                                                   sep=" - ")))
progresso_data2 <- data_subset %>% 
  rowwise() %>% 
  mutate(semanas = lubridate::time_length(
                   lubridate::interval(
                   lubridate::ymd(unlist(strsplit(as.character(data_inicio), " "))[1]), 
                   lubridate::ymd(hoje)), "week")) %>%           
  filter(!is.na(data_inicio))

p <- progresso_data2 %>%
  plotly::plot_ly(
    x = ~fase_global, 
    y = ~apelido, 
    color = ~tema, 
    frame = ~semanas, 
    text = ~as.character(apelido), 
    hoverinfo = "text",
    type = 'scatter',
    mode = 'markers'
  )
plotly::ggplotly(p)
## Warning in p$x$data[firstFrame] <- p$x$frames[[1]]$data: number of items to
## replace is not a multiple of replacement length

Matheus Leal

2019-05-20